

type checkType = 'address' | 'amount' | 'name' | 'password' | 'mobile'| 'price' | 'verifyCode' ;

const checkRules = {
    amount: /^[1-9]\d{0,7}\.\d{0,8}$|^0\.\d{0,8}$|^[1-9]\d{0,7}$/,
    name: /^user\d{2}$|^1[3-9]\d{9}$/,
    mobile: /^1[3-9]\d{9}/,
    password: /(?![0-9]+$)(?![a-zA-Z]+$)(?![\x21-\x2f\x3a-\x40\x5b-\x60\x7B-\x7F\uFF00-\uFFFF]+$)^[\x21-\x2f\x3a-\x40\x5b-\x60\x7B-\x7F0-9A-Za-z]{8,32}$/,
    address: /^\w+$/,
    price: /^[1-9]\d{0,7}\.\d{0,8}$|^0\.\d{0,8}$|^[1-9]\d{0,7}$/,
    verifyCode: /^\d{4}$/,
    ETH: /^0x[0-9a-fA-F]{40}$/,
    BTC:  /^1[0-9a-zA-Z]{33}$/,
}

const utilValidCheck = (data: string | number, type: checkType) : boolean => {
    let _data = String(data);
    if (checkRules[type]) {
        return checkRules[type].test(_data);
    }
    return false;
}

export {
    utilValidCheck
}